namespace com.excel.utils;

public class Demo {
    public void create() {
        Workbook workbook = new XSSFWorkbook();
        ExcelUtil excelUtil = new ExcelUtil(workbook);
        excelUtil.createSheet();
        try {
            excelUtil.setSheetName(0, "司机收支明细");
        } catch (IOException e) {
            log.error("Excel创建失败:", e);
            return;
        }

        // 获取excel数据
        List<List<Object>> rowData = convertDriverDetailData(params);

        Font font = excelUtil.getWorkbook().createFont();
        font.setColor(IndexedColors.RED.index);
        CellStyle cellStyle = excelUtil.getWorkbook().createCellStyle();
        DataFormat format = excelUtil.getWorkbook().createDataFormat();
        cellStyle.setDataFormat(format.getFormat("¥#,##0"));
        cellStyle.setFont(font);

        Sheet sheet = workbook.getSheetAt(0);
        sheet.setColumnWidth(0, 4000);
        sheet.setColumnWidth(1, 2500);
        sheet.setColumnWidth(2, 2500);
        sheet.setColumnWidth(3, 5000);
        sheet.setColumnWidth(4, 3500);
        sheet.setColumnWidth(5, 3500);
        sheet.setColumnWidth(6, 2500);
        sheet.setColumnWidth(7, 2500);
        sheet.setColumnWidth(8, 2500);
        sheet.setColumnWidth(9, 2500);
        sheet.setColumnWidth(10, 6000);
        sheet.setColumnWidth(11, 6000);
        sheet.setColumnWidth(12, 4000);

        List<String> cellTypeList = new ArrayList<>();
        cellTypeList.add(ExcelConstants.STRING_TYPE);
        cellTypeList.add(ExcelConstants.STRING_TYPE);
        cellTypeList.add(ExcelConstants.STRING_TYPE);
        cellTypeList.add(ExcelConstants.STRING_TYPE);
        cellTypeList.add(ExcelConstants.STRING_TYPE);
        cellTypeList.add(ExcelConstants.STRING_TYPE);
        cellTypeList.add(ExcelConstants.MONEY_TYPE);
        cellTypeList.add(ExcelConstants.MONEY_TYPE);
        cellTypeList.add(ExcelConstants.MONEY_TYPE);
        cellTypeList.add(ExcelConstants.STRING_TYPE);
        cellTypeList.add(ExcelConstants.STRING_TYPE);
        cellTypeList.add(ExcelConstants.STRING_TYPE);
        cellTypeList.add(ExcelConstants.STRING_TYPE);

        try {
            excelUtil.write(rowData, cellTypeList);
        } catch (IOException e) {
            log.error("数据写入失败:", e);
            return;
        }
        try {
            excelUtil.setOs(new FileOutputStream(filePath));
        } catch (FileNotFoundException e) {
            log.error("设置文件流失败:", e);
            return;
        }
        // 创建Excel文件
        excelUtil.createExcel(workbook, excelUtil.getOs());
    }
}
